/*   1:    */ package org.intellij.images.thumbnail.impl;
/*   2:    */ 
/*   3:    */

import com.intellij.ide.CopyPasteSupport;
import com.intellij.ide.DeleteProvider;
import com.intellij.ide.PsiActionSupportFactory;
import com.intellij.ide.PsiActionSupportFactory.PsiElementSelector;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.fileEditor.FileEditorManager;
import com.intellij.openapi.fileTypes.FileTypeManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.roots.ProjectRootManager;
import com.intellij.openapi.vfs.*;
import com.intellij.pom.Navigatable;
import com.intellij.psi.PsiDirectory;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiManager;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.ui.IdeBorderFactory;
import com.intellij.ui.ScrollPaneFactory;
import com.intellij.ui.components.JBList;
import org.intellij.images.fileTypes.ImageFileTypeManager;
import org.intellij.images.options.*;
import org.intellij.images.thumbnail.ThumbnailView;
import org.intellij.images.ui.ImageComponent;
import org.intellij.images.ui.ImageComponentDecorator;
import org.intellij.images.ui.ThumbnailComponent;
import org.intellij.images.ui.ThumbnailComponentUI;
import org.intellij.images.vfs.IfsUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionListener;
import java.awt.image.BufferedImage;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;

/*   4:    */
/*   5:    */
/*   6:    */
/*   7:    */
/*   8:    */
/*   9:    */
/*  10:    */
/*  11:    */
/*  12:    */
/*  13:    */
/*  14:    */
/*  15:    */
/*  16:    */
/*  17:    */
/*  18:    */
/*  19:    */
/*  20:    */
/*  21:    */
/*  22:    */
/*  23:    */
/*  24:    */
/*  25:    */
/*  26:    */
/*  27:    */
/*  28:    */
/*  29:    */
/*  30:    */
/*  31:    */
/*  32:    */
/*  33:    */
/*  34:    */
/*  35:    */
/*  36:    */
/*  37:    */
/*  38:    */
/*  39:    */
/*  40:    */
/*  41:    */
/*  42:    */
/*  43:    */
/*  44:    */
/*  45:    */
/*  46:    */
/*  47:    */
/*  48:    */
/*  49:    */
/*  50:    */
/*  51:    */
/*  52:    */
/*  53:    */
/*  54:    */
/*  55:    */
/*  56:    */
/*  57:    */
/*  58:    */
/*  59:    */
/*  60:    */
/*  61:    */
/*  62:    */
/*  63:    */
/*  64:    */
/*  65:    */
/*  66:    */
/*  67:    */
/*  68:    */
/*  69:    */
/*  70:    */
/*  71:    */
/*  72:    */
/*  73:    */
/*  74:    */
/*  75:    */
/*  76:    */
/*  77:    */
/*  78:    */ 
/*  79:    */ final class ThumbnailViewUI
/*  80:    */   extends JPanel
/*  81:    */   implements DataProvider, Disposable
/*  82:    */ {
/*  83: 64 */   private final VirtualFileListener a = new VFSListener(null);
/*  84: 65 */   private final OptionsChangeListener b = new OptionsChangeListener(null);
/*  85: 67 */   private static final Navigatable[] c = new Navigatable[0];
/*  86:    */   private final ThumbnailView d;
/*  87:    */   private final CopyPasteSupport e;
/*  88:    */   private final DeleteProvider f;
/*  89:    */   private ThumbnailListCellRenderer g;
/*  90:    */   private JList h;
/*  91: 74 */   private static final Comparator<VirtualFile> i = new Comparator()
/*  92:    */   {
/*  93:    */     public int compare(VirtualFile paramAnonymousVirtualFile1, VirtualFile paramAnonymousVirtualFile2)
/*  94:    */     {
/*  95: 76 */       if ((paramAnonymousVirtualFile1.isDirectory()) && (!paramAnonymousVirtualFile2.isDirectory())) {
/*  96: 77 */         return -1;
/*  97:    */       }
/*  98: 79 */       if ((paramAnonymousVirtualFile2.isDirectory()) && (!paramAnonymousVirtualFile1.isDirectory())) {
/*  99: 80 */         return 1;
/* 100:    */       }
/* 101: 83 */       return paramAnonymousVirtualFile1.getPath().toLowerCase().compareTo(paramAnonymousVirtualFile2.getPath().toLowerCase());
/* 102:    */     }
/* 103:    */   };
/* 104:    */   
/* 105:    */   public ThumbnailViewUI(ThumbnailViewImpl paramThumbnailViewImpl)
/* 106:    */   {
/* 107: 88 */     super(new BorderLayout());
/* 108:    */     
/* 109: 90 */     this.d = paramThumbnailViewImpl;
/* 110:    */     
/* 111: 92 */     PsiActionSupportFactory localPsiActionSupportFactory = PsiActionSupportFactory.getInstance();
/* 112: 93 */     this.e = localPsiActionSupportFactory.createPsiBasedCopyPasteSupport(paramThumbnailViewImpl.getProject(), this, new PsiActionSupportFactory.PsiElementSelector()
/* 113:    */     {
/* 114:    */       public PsiElement[] getSelectedElements()
/* 115:    */       {
/* 116: 95 */         return (PsiElement[])ThumbnailViewUI.this.getData(LangDataKeys.PSI_ELEMENT_ARRAY.getName());
/* 117:    */       }
/* 118: 98 */     });
/* 119: 99 */     this.f = localPsiActionSupportFactory.createPsiBasedDeleteProvider();
/* 120:    */   }
/* 121:    */   
/* 122:    */   private void a()
/* 123:    */   {
/* 124:104 */     if ((this.g == null) || (this.h == null))
/* 125:    */     {
/* 126:105 */       this.g = new ThumbnailListCellRenderer(null);
/* 127:106 */       ImageComponent localImageComponent = this.g.getImageComponent();
/* 128:    */       
/* 129:108 */       VirtualFileManager.getInstance().addVirtualFileListener(this.a);
/* 130:    */       
/* 131:110 */       Options localOptions = OptionsManager.getInstance().getOptions();
/* 132:111 */       EditorOptions localEditorOptions = localOptions.getEditorOptions();
/* 133:    */       
/* 134:113 */       TransparencyChessboardOptions localTransparencyChessboardOptions = localEditorOptions.getTransparencyChessboardOptions();
/* 135:114 */       localImageComponent.setTransparencyChessboardVisible(localTransparencyChessboardOptions.isShowDefault());
/* 136:115 */       localImageComponent.setTransparencyChessboardCellSize(localTransparencyChessboardOptions.getCellSize());
/* 137:116 */       localImageComponent.setTransparencyChessboardWhiteColor(localTransparencyChessboardOptions.getWhiteColor());
/* 138:117 */       localImageComponent.setTransparencyChessboardBlankColor(localTransparencyChessboardOptions.getBlackColor());
/* 139:    */       
/* 140:119 */       localOptions.addPropertyChangeListener(this.b);
/* 141:    */       
/* 142:121 */       this.h = new JBList();
/* 143:122 */       this.h.setModel(new DefaultListModel());
/* 144:123 */       this.h.setLayoutOrientation(2);
/* 145:124 */       this.h.setVisibleRowCount(-1);
/* 146:125 */       this.h.setCellRenderer(this.g);
/* 147:126 */       this.h.setSelectionMode(2);
/* 148:    */       
/* 149:128 */       ThumbnailsMouseAdapter localThumbnailsMouseAdapter = new ThumbnailsMouseAdapter(null);
/* 150:129 */       this.h.addMouseListener(localThumbnailsMouseAdapter);
/* 151:130 */       this.h.addMouseMotionListener(localThumbnailsMouseAdapter);
/* 152:    */       
/* 153:132 */       ThumbnailComponentUI localThumbnailComponentUI = (ThumbnailComponentUI)UIManager.getUI(this.g);
/* 154:133 */       Dimension localDimension = localThumbnailComponentUI.getPreferredSize(this.g);
/* 155:    */       
/* 156:135 */       this.h.setFixedCellWidth(localDimension.width);
/* 157:136 */       this.h.setFixedCellHeight(localDimension.height);
/* 158:    */       
/* 159:    */ 
/* 160:139 */       JScrollPane localJScrollPane = ScrollPaneFactory.createScrollPane(this.h, 20, 31);
/* 161:    */       
/* 162:    */ 
/* 163:142 */       localJScrollPane.setBorder(IdeBorderFactory.createBorder(2));
/* 164:    */       
/* 165:144 */       ActionManager localActionManager = ActionManager.getInstance();
/* 166:145 */       ActionGroup localActionGroup = (ActionGroup)localActionManager.getAction("Images.ThumbnailsToolbar");
/* 167:146 */       ActionToolbar localActionToolbar = localActionManager.createActionToolbar("Images.Thumbnails", localActionGroup, true);
/* 168:    */       
/* 169:    */ 
/* 170:149 */       localActionToolbar.setTargetComponent(this);
/* 171:    */       
/* 172:151 */       JComponent localJComponent = localActionToolbar.getComponent();
/* 173:    */       
/* 174:153 */       FocusRequester localFocusRequester = new FocusRequester(null);
/* 175:154 */       localJComponent.addMouseListener(localFocusRequester);
/* 176:155 */       localJScrollPane.addMouseListener(localFocusRequester);
/* 177:    */       
/* 178:157 */       add(localJComponent, "North");
/* 179:158 */       add(localJScrollPane, "Center");
/* 180:    */     }
/* 181:    */   }
/* 182:    */   
/* 183:    */   public void refresh()
/* 184:    */   {
/* 185:163 */     a();
/* 186:164 */     if (this.h != null)
/* 187:    */     {
/* 188:165 */       DefaultListModel localDefaultListModel = (DefaultListModel)this.h.getModel();
/* 189:166 */       localDefaultListModel.clear();
/* 190:167 */       VirtualFile localVirtualFile1 = this.d.getRoot();
/* 191:168 */       if ((localVirtualFile1 != null) && (localVirtualFile1.isValid()) && (localVirtualFile1.isDirectory()))
/* 192:    */       {
/* 193:169 */         Set localSet = a(localVirtualFile1.getChildren());
/* 194:170 */         VirtualFile[] arrayOfVirtualFile1 = VfsUtil.toVirtualFileArray(localSet);
/* 195:171 */         Arrays.sort(arrayOfVirtualFile1, i);
/* 196:    */         
/* 197:173 */         localDefaultListModel.ensureCapacity(localDefaultListModel.size() + arrayOfVirtualFile1.length + 1);
/* 198:174 */         for (VirtualFile localVirtualFile2 : arrayOfVirtualFile1) {
/* 199:175 */           localDefaultListModel.addElement(localVirtualFile2);
/* 200:    */         }
/* 201:177 */         if (localDefaultListModel.size() > 0) {
/* 202:178 */           this.h.setSelectedIndex(0);
/* 203:    */         }
/* 204:    */       }
/* 205:    */       else
/* 206:    */       {
/* 207:181 */         this.d.setVisible(false);
/* 208:    */       }
/* 209:    */     }
/* 210:    */   }
/* 211:    */   
/* 212:    */   public boolean isTransparencyChessboardVisible()
/* 213:    */   {
/* 214:187 */     a();
/* 215:188 */     return this.g.getImageComponent().isTransparencyChessboardVisible();
/* 216:    */   }
/* 217:    */   
/* 218:    */   public void setTransparencyChessboardVisible(boolean paramBoolean)
/* 219:    */   {
/* 220:192 */     a();
/* 221:193 */     this.g.getImageComponent().setTransparencyChessboardVisible(paramBoolean);
/* 222:194 */     this.h.repaint();
/* 223:    */   }
/* 224:    */   
/* 225:    */   public void setSelected(VirtualFile paramVirtualFile, boolean paramBoolean)
/* 226:    */   {
/* 227:198 */     a();
/* 228:199 */     this.h.setSelectedValue(paramVirtualFile, false);
/* 229:    */   }
/* 230:    */   
/* 231:    */   public void scrollToSelection()
/* 232:    */   {
/* 233:203 */     int j = this.h.getMinSelectionIndex();
/* 234:204 */     int k = this.h.getMaxSelectionIndex();
/* 235:205 */     if ((j != -1) && (k != -1)) {
/* 236:206 */       this.h.scrollRectToVisible(this.h.getCellBounds(j, k));
/* 237:    */     }
/* 238:    */   }
/* 239:    */   
/* 240:    */   public boolean isSelected(VirtualFile paramVirtualFile)
/* 241:    */   {
/* 242:211 */     int j = ((DefaultListModel)this.h.getModel()).indexOf(paramVirtualFile);
/* 243:212 */     return (j != -1) && (this.h.isSelectedIndex(j));
/* 244:    */   }
/* 245:    */   
/* 246:    */   @NotNull
/* 247:    */   public VirtualFile[] getSelection()
/* 248:    */   {
/* 249:217 */     if (this.h != null)
/* 250:    */     {
/* 251:218 */       Object[] arrayOfObject = this.h.getSelectedValues();
/* 252:219 */       if (arrayOfObject != null)
/* 253:    */       {
/* 254:220 */         VirtualFile[] arrayOfVirtualFile = new VirtualFile[arrayOfObject.length];
/* 255:221 */         for (int j = 0; j < arrayOfObject.length; j++) {
/* 256:222 */           arrayOfVirtualFile[j] = ((VirtualFile)arrayOfObject[j]);
/* 257:    */         }
/* 258:224 */         VirtualFile[] tmp49_48 = arrayOfVirtualFile;
/* 259:224 */         if (tmp49_48 == null) {
/* 260:224 */           throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/images/thumbnail/impl/ThumbnailViewUI", "getSelection" }));
/* 261:    */         }
/* 262:224 */         return tmp49_48;
/* 263:    */       }
/* 264:    */     }
/* 265:227 */     VirtualFile[] tmp93_90 = VirtualFile.EMPTY_ARRAY;
/* 266:227 */     if (tmp93_90 == null) {
/* 267:227 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/images/thumbnail/impl/ThumbnailViewUI", "getSelection" }));
/* 268:    */     }
/* 269:227 */     return tmp93_90;
/* 270:    */   }
/* 271:    */   
/* 272:    */   private final class ThumbnailListCellRenderer
/* 273:    */     extends ThumbnailComponent
/* 274:    */     implements ListCellRenderer
/* 275:    */   {
/* 276:232 */     private final ImageFileTypeManager m = ImageFileTypeManager.getInstance();
/* 277:    */     
/* 278:    */     private ThumbnailListCellRenderer() {}
/* 279:    */     
/* 280:    */     public Component getListCellRendererComponent(JList paramJList, Object paramObject, int paramInt, boolean paramBoolean1, boolean paramBoolean2)
/* 281:    */     {
/* 282:    */       Object localObject1;
/* 283:237 */       if ((paramObject instanceof VirtualFile))
/* 284:    */       {
/* 285:238 */         localObject1 = (VirtualFile)paramObject;
/* 286:239 */         setFileName(((VirtualFile)localObject1).getName());
/* 287:240 */         setToolTipText(IfsUtil.getReferencePath(ThumbnailViewUI.this.d.getProject(), (VirtualFile)localObject1));
/* 288:241 */         setDirectory(((VirtualFile)localObject1).isDirectory());
/* 289:    */         Object localObject2;
/* 290:242 */         if (((VirtualFile)localObject1).isDirectory())
/* 291:    */         {
/* 292:243 */           int i = 0;
/* 293:244 */           localObject2 = ((VirtualFile)localObject1).getChildren();
/* 294:245 */           for (VirtualFile localVirtualFile : localObject2) {
/* 295:246 */             if (this.m.isImage(localVirtualFile))
/* 296:    */             {
/* 297:247 */               i++;
/* 298:248 */               if (i > 100) {
/* 299:    */                 break;
/* 300:    */               }
/* 301:    */             }
/* 302:    */           }
/* 303:253 */           setImagesCount(i);
/* 304:    */         }
/* 305:    */         else
/* 306:    */         {
/* 307:256 */           setFileSize(((VirtualFile)localObject1).getLength());
/* 308:    */           try
/* 309:    */           {
/* 310:258 */             BufferedImage localBufferedImage = IfsUtil.getImage((VirtualFile)localObject1);
/* 311:259 */             localObject2 = getImageComponent();
/* 312:260 */             ((ImageComponent)localObject2).getDocument().setValue(localBufferedImage);
/* 313:261 */             setFormat(IfsUtil.getFormat((VirtualFile)localObject1));
/* 314:    */           }
/* 315:    */           catch (Exception localException)
/* 316:    */           {
/* 317:264 */             localObject2 = getImageComponent();
/* 318:265 */             ((ImageComponent)localObject2).getDocument().setValue(null);
/* 319:    */           }
/* 320:    */         }
/* 321:    */       }
/* 322:    */       else
/* 323:    */       {
/* 324:270 */         localObject1 = getImageComponent();
/* 325:271 */         ((ImageComponent)localObject1).getDocument().setValue(null);
/* 326:272 */         setFileName(null);
/* 327:273 */         setFileSize(0L);
/* 328:274 */         setToolTipText(null);
/* 329:    */       }
/* 330:277 */       if (paramBoolean1)
/* 331:    */       {
/* 332:278 */         setForeground(paramJList.getSelectionForeground());
/* 333:279 */         setBackground(paramJList.getSelectionBackground());
/* 334:    */       }
/* 335:    */       else
/* 336:    */       {
/* 337:281 */         setForeground(paramJList.getForeground());
/* 338:282 */         setBackground(paramJList.getBackground());
/* 339:    */       }
/* 340:285 */       return this;
/* 341:    */     }
/* 342:    */   }
/* 343:    */   
/* 344:    */   private Set<VirtualFile> a(VirtualFile[] paramArrayOfVirtualFile)
/* 345:    */   {
/* 346:291 */     HashSet localHashSet = new HashSet();
/* 347:292 */     for (VirtualFile localVirtualFile : paramArrayOfVirtualFile) {
/* 348:293 */       localHashSet.addAll(a(localVirtualFile));
/* 349:    */     }
/* 350:295 */     return localHashSet;
/* 351:    */   }
/* 352:    */   
/* 353:    */   private Set<VirtualFile> a(VirtualFile paramVirtualFile)
/* 354:    */   {
/* 355:299 */     HashSet localHashSet = new HashSet(0);
/* 356:300 */     Project localProject = this.d.getProject();
/* 357:301 */     if (!localProject.isDisposed())
/* 358:    */     {
/* 359:302 */       ProjectRootManager localProjectRootManager = ProjectRootManager.getInstance(localProject);
/* 360:303 */       boolean bool = localProjectRootManager.getFileIndex().isIgnored(paramVirtualFile);
/* 361:305 */       if ((!bool) && (!FileTypeManager.getInstance().isFileIgnored(paramVirtualFile)))
/* 362:    */       {
/* 363:306 */         ImageFileTypeManager localImageFileTypeManager = ImageFileTypeManager.getInstance();
/* 364:307 */         if (paramVirtualFile.isDirectory())
/* 365:    */         {
/* 366:308 */           if (this.d.isRecursive()) {
/* 367:309 */             localHashSet.addAll(a(paramVirtualFile.getChildren()));
/* 368:310 */           } else if (b(paramVirtualFile)) {
/* 369:311 */             localHashSet.add(paramVirtualFile);
/* 370:    */           }
/* 371:    */         }
/* 372:313 */         else if (localImageFileTypeManager.isImage(paramVirtualFile)) {
/* 373:314 */           localHashSet.add(paramVirtualFile);
/* 374:    */         }
/* 375:    */       }
/* 376:    */     }
/* 377:318 */     return localHashSet;
/* 378:    */   }
/* 379:    */   
/* 380:    */   private boolean b(VirtualFile paramVirtualFile)
/* 381:    */   {
/* 382:322 */     ImageFileTypeManager localImageFileTypeManager = ImageFileTypeManager.getInstance();
/* 383:323 */     VirtualFile[] arrayOfVirtualFile1 = paramVirtualFile.getChildren();
/* 384:324 */     for (VirtualFile localVirtualFile : arrayOfVirtualFile1)
/* 385:    */     {
/* 386:325 */       if (localVirtualFile.isDirectory()) {
/* 387:327 */         return true;
/* 388:    */       }
/* 389:329 */       if (localImageFileTypeManager.isImage(localVirtualFile)) {
/* 390:330 */         return true;
/* 391:    */       }
/* 392:    */     }
/* 393:333 */     return false;
/* 394:    */   }
/* 395:    */   
/* 396:    */   private final class ThumbnailsMouseAdapter
/* 397:    */     extends MouseAdapter
/* 398:    */     implements MouseMotionListener
/* 399:    */   {
/* 400:    */     private ThumbnailsMouseAdapter() {}
/* 401:    */     
/* 402:    */     public void mouseDragged(MouseEvent paramMouseEvent)
/* 403:    */     {
/* 404:338 */       Point localPoint = paramMouseEvent.getPoint();
/* 405:339 */       int i = ThumbnailViewUI.this.h.locationToIndex(localPoint);
/* 406:340 */       if (i != -1)
/* 407:    */       {
/* 408:341 */         Rectangle localRectangle = ThumbnailViewUI.this.h.getCellBounds(i, i);
/* 409:342 */         if ((!localRectangle.contains(localPoint)) && ((0x80 & paramMouseEvent.getModifiersEx()) != 128))
/* 410:    */         {
/* 411:344 */           ThumbnailViewUI.this.h.clearSelection();
/* 412:345 */           paramMouseEvent.consume();
/* 413:    */         }
/* 414:    */       }
/* 415:    */     }
/* 416:    */     
/* 417:    */     public void mouseMoved(MouseEvent paramMouseEvent) {}
/* 418:    */     
/* 419:    */     public void mousePressed(MouseEvent paramMouseEvent)
/* 420:    */     {
/* 421:355 */       Point localPoint = paramMouseEvent.getPoint();
/* 422:356 */       int i = ThumbnailViewUI.this.h.locationToIndex(localPoint);
/* 423:357 */       if (i != -1)
/* 424:    */       {
/* 425:358 */         Rectangle localRectangle = ThumbnailViewUI.this.h.getCellBounds(i, i);
/* 426:359 */         if ((!localRectangle.contains(localPoint)) && ((0x80 & paramMouseEvent.getModifiersEx()) != 128))
/* 427:    */         {
/* 428:360 */           ThumbnailViewUI.this.h.clearSelection();
/* 429:361 */           paramMouseEvent.consume();
/* 430:    */         }
/* 431:    */       }
/* 432:    */     }
/* 433:    */     
/* 434:    */     public void mouseClicked(MouseEvent paramMouseEvent)
/* 435:    */     {
/* 436:367 */       Point localPoint = paramMouseEvent.getPoint();
/* 437:368 */       int i = ThumbnailViewUI.this.h.locationToIndex(localPoint);
/* 438:    */       Object localObject1;
/* 439:369 */       if (i != -1)
/* 440:    */       {
/* 441:370 */         localObject1 = ThumbnailViewUI.this.h.getCellBounds(i, i);
/* 442:371 */         if ((!((Rectangle)localObject1).contains(localPoint)) && ((0x80 & paramMouseEvent.getModifiersEx()) != 128))
/* 443:    */         {
/* 444:372 */           i = -1;
/* 445:373 */           ThumbnailViewUI.this.h.clearSelection();
/* 446:    */         }
/* 447:    */       }
/* 448:376 */       if (i != -1)
/* 449:    */       {
/* 450:    */         Object localObject2;
/* 451:377 */         if ((1 == paramMouseEvent.getButton()) && (paramMouseEvent.getClickCount() == 2))
/* 452:    */         {
/* 453:379 */           ThumbnailViewUI.this.h.setSelectedIndex(i);
/* 454:380 */           localObject1 = (VirtualFile)ThumbnailViewUI.this.h.getSelectedValue();
/* 455:381 */           if (localObject1 != null)
/* 456:    */           {
/* 457:382 */             if (((VirtualFile)localObject1).isDirectory())
/* 458:    */             {
/* 459:383 */               ThumbnailViewUI.this.d.setRoot((VirtualFile)localObject1);
/* 460:    */             }
/* 461:    */             else
/* 462:    */             {
/* 463:385 */               localObject2 = FileEditorManager.getInstance(ThumbnailViewUI.this.d.getProject());
/* 464:386 */               ((FileEditorManager)localObject2).openFile((VirtualFile)localObject1, true);
/* 465:    */             }
/* 466:388 */             paramMouseEvent.consume();
/* 467:    */           }
/* 468:    */         }
/* 469:391 */         if ((3 == paramMouseEvent.getButton()) && (paramMouseEvent.getClickCount() == 1))
/* 470:    */         {
/* 471:393 */           if ((0x80 & paramMouseEvent.getModifiersEx()) != 128) {
/* 472:395 */             ThumbnailViewUI.this.h.setSelectedIndex(i);
/* 473:    */           } else {
/* 474:398 */             ThumbnailViewUI.this.h.getSelectionModel().addSelectionInterval(i, i);
/* 475:    */           }
/* 476:401 */           localObject1 = ActionManager.getInstance();
/* 477:402 */           localObject2 = (ActionGroup)((ActionManager)localObject1).getAction("Images.ThumbnailsPopupMenu");
/* 478:403 */           ActionPopupMenu localActionPopupMenu = ((ActionManager)localObject1).createActionPopupMenu("Images.Thumbnails", (ActionGroup)localObject2);
/* 479:404 */           JPopupMenu localJPopupMenu = localActionPopupMenu.getComponent();
/* 480:405 */           localJPopupMenu.pack();
/* 481:406 */           localJPopupMenu.show(paramMouseEvent.getComponent(), paramMouseEvent.getX(), paramMouseEvent.getY());
/* 482:    */           
/* 483:408 */           paramMouseEvent.consume();
/* 484:    */         }
/* 485:    */       }
/* 486:    */     }
/* 487:    */   }
/* 488:    */   
/* 489:    */   @Nullable
/* 490:    */   public Object getData(String paramString)
/* 491:    */   {
/* 492:416 */     if (CommonDataKeys.PROJECT.is(paramString)) {
/* 493:417 */       return this.d.getProject();
/* 494:    */     }
/* 495:    */     VirtualFile[] arrayOfVirtualFile1;
/* 496:418 */     if (CommonDataKeys.VIRTUAL_FILE.is(paramString))
/* 497:    */     {
/* 498:419 */       arrayOfVirtualFile1 = c();
/* 499:420 */       return arrayOfVirtualFile1.length > 0 ? arrayOfVirtualFile1[0] : null;
/* 500:    */     }
/* 501:421 */     if (CommonDataKeys.VIRTUAL_FILE_ARRAY.is(paramString)) {
/* 502:422 */       return c();
/* 503:    */     }
/* 504:423 */     if (CommonDataKeys.PSI_FILE.is(paramString)) {
/* 505:424 */       return getData(CommonDataKeys.PSI_ELEMENT.getName());
/* 506:    */     }
/* 507:425 */     if (CommonDataKeys.PSI_ELEMENT.is(paramString))
/* 508:    */     {
/* 509:426 */       arrayOfVirtualFile1 = c();
/* 510:427 */       return arrayOfVirtualFile1.length > 0 ? PsiManager.getInstance(this.d.getProject()).findFile(arrayOfVirtualFile1[0]) : null;
/* 511:    */     }
/* 512:428 */     if (LangDataKeys.PSI_ELEMENT_ARRAY.is(paramString)) {
/* 513:429 */       return b();
/* 514:    */     }
/* 515:430 */     if (CommonDataKeys.NAVIGATABLE.is(paramString))
/* 516:    */     {
/* 517:431 */       arrayOfVirtualFile1 = c();
/* 518:432 */       return new ThumbnailNavigatable(arrayOfVirtualFile1.length > 0 ? arrayOfVirtualFile1[0] : null);
/* 519:    */     }
/* 520:433 */     if (PlatformDataKeys.COPY_PROVIDER.is(paramString)) {
/* 521:434 */       return this.e.getCopyProvider();
/* 522:    */     }
/* 523:435 */     if (PlatformDataKeys.CUT_PROVIDER.is(paramString)) {
/* 524:436 */       return this.e.getCutProvider();
/* 525:    */     }
/* 526:437 */     if (PlatformDataKeys.PASTE_PROVIDER.is(paramString)) {
/* 527:438 */       return this.e.getPasteProvider();
/* 528:    */     }
/* 529:439 */     if (PlatformDataKeys.DELETE_ELEMENT_PROVIDER.is(paramString)) {
/* 530:440 */       return this.f;
/* 531:    */     }
/* 532:441 */     if (CommonDataKeys.NAVIGATABLE_ARRAY.is(paramString))
/* 533:    */     {
/* 534:442 */       arrayOfVirtualFile1 = c();
/* 535:443 */       HashSet localHashSet = new HashSet(arrayOfVirtualFile1.length);
/* 536:444 */       for (VirtualFile localVirtualFile : arrayOfVirtualFile1) {
/* 537:445 */         if (!localVirtualFile.isDirectory()) {
/* 538:446 */           localHashSet.add(new ThumbnailNavigatable(localVirtualFile));
/* 539:    */         }
/* 540:    */       }
/* 541:449 */       return localHashSet.toArray(c);
/* 542:    */     }
/* 543:450 */     if (ThumbnailView.DATA_KEY.is(paramString)) {
/* 544:451 */       return this.d;
/* 545:    */     }
/* 546:452 */     if (ImageComponentDecorator.DATA_KEY.is(paramString)) {
/* 547:453 */       return this.d;
/* 548:    */     }
/* 549:456 */     return null;
/* 550:    */   }
/* 551:    */   
/* 552:    */   @NotNull
/* 553:    */   private PsiElement[] b()
/* 554:    */   {
/* 555:462 */     VirtualFile[] arrayOfVirtualFile1 = c();
/* 556:463 */     HashSet localHashSet = new HashSet(arrayOfVirtualFile1.length);
/* 557:464 */     PsiManager localPsiManager = PsiManager.getInstance(this.d.getProject());
/* 558:465 */     for (VirtualFile localVirtualFile : arrayOfVirtualFile1)
/* 559:    */     {
/* 560:466 */       PsiFile localPsiFile = localPsiManager.findFile(localVirtualFile);
/* 561:467 */       PsiDirectory localPsiDirectory = localPsiFile != null ? localPsiFile : localPsiManager.findDirectory(localVirtualFile);
/* 562:468 */       if (localPsiDirectory != null) {
/* 563:469 */         localHashSet.add(localPsiDirectory);
/* 564:    */       }
/* 565:    */     }
/* 566:472 */     PsiElement[] tmp103_100 = PsiUtilCore.toPsiElementArray(localHashSet);
/* 567:472 */     if (tmp103_100 == null) {
/* 568:472 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/images/thumbnail/impl/ThumbnailViewUI", "getSelectedElements" }));
/* 569:    */     }
/* 570:472 */     return tmp103_100;
/* 571:    */   }
/* 572:    */   
/* 573:    */   @NotNull
/* 574:    */   private VirtualFile[] c()
/* 575:    */   {
/* 576:477 */     if (this.h != null)
/* 577:    */     {
/* 578:478 */       Object[] arrayOfObject = this.h.getSelectedValues();
/* 579:479 */       if (arrayOfObject != null)
/* 580:    */       {
/* 581:480 */         VirtualFile[] arrayOfVirtualFile = new VirtualFile[arrayOfObject.length];
/* 582:481 */         for (int j = 0; j < arrayOfObject.length; j++) {
/* 583:482 */           arrayOfVirtualFile[j] = ((VirtualFile)arrayOfObject[j]);
/* 584:    */         }
/* 585:484 */         VirtualFile[] tmp49_48 = arrayOfVirtualFile;
/* 586:484 */         if (tmp49_48 == null) {
/* 587:484 */           throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/images/thumbnail/impl/ThumbnailViewUI", "getSelectedFiles" }));
/* 588:    */         }
/* 589:484 */         return tmp49_48;
/* 590:    */       }
/* 591:    */     }
/* 592:487 */     VirtualFile[] tmp93_90 = VirtualFile.EMPTY_ARRAY;
/* 593:487 */     if (tmp93_90 == null) {
/* 594:487 */       throw new IllegalStateException(String.format("@NotNull method %s.%s must not return null", new Object[] { "org/intellij/images/thumbnail/impl/ThumbnailViewUI", "getSelectedFiles" }));
/* 595:    */     }
/* 596:487 */     return tmp93_90;
/* 597:    */   }
/* 598:    */   
/* 599:    */   public void dispose()
/* 600:    */   {
/* 601:491 */     removeAll();
/* 602:    */     
/* 603:493 */     Options localOptions = OptionsManager.getInstance().getOptions();
/* 604:494 */     localOptions.removePropertyChangeListener(this.b);
/* 605:    */     
/* 606:496 */     VirtualFileManager.getInstance().removeVirtualFileListener(this.a);
/* 607:    */     
/* 608:498 */     this.h = null;
/* 609:499 */     this.g = null;
/* 610:    */   }
/* 611:    */   
/* 612:    */   private final class ThumbnailNavigatable
/* 613:    */     implements Navigatable
/* 614:    */   {
/* 615:    */     private final VirtualFile a;
/* 616:    */     
/* 617:    */     public ThumbnailNavigatable(VirtualFile paramVirtualFile)
/* 618:    */     {
/* 619:506 */       this.a = paramVirtualFile;
/* 620:    */     }
/* 621:    */     
/* 622:    */     public void navigate(boolean paramBoolean)
/* 623:    */     {
/* 624:510 */       if (this.a != null)
/* 625:    */       {
/* 626:511 */         FileEditorManager localFileEditorManager = FileEditorManager.getInstance(ThumbnailViewUI.this.d.getProject());
/* 627:512 */         localFileEditorManager.openFile(this.a, true);
/* 628:    */       }
/* 629:    */     }
/* 630:    */     
/* 631:    */     public boolean canNavigate()
/* 632:    */     {
/* 633:517 */       return this.a != null;
/* 634:    */     }
/* 635:    */     
/* 636:    */     public boolean canNavigateToSource()
/* 637:    */     {
/* 638:521 */       return this.a != null;
/* 639:    */     }
/* 640:    */   }
/* 641:    */   
/* 642:    */   private final class VFSListener
/* 643:    */     extends VirtualFileAdapter
/* 644:    */   {
/* 645:    */     VFSListener(ThumbnailViewUI.1 param1)
/* 646:    */     {
/* 647:525 */       this();
/* 648:    */     }
/* 649:    */     
/* 650:    */     public void contentsChanged(@NotNull VirtualFileEvent paramVirtualFileEvent)
/* 651:    */     {
/* 652:527 */       if (paramVirtualFileEvent == null) {
/* 653:527 */         throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/images/thumbnail/impl/ThumbnailViewUI$VFSListener", "contentsChanged" }));
/* 654:    */       }
/* 655:527 */       VirtualFile localVirtualFile = paramVirtualFileEvent.getFile();
/* 656:528 */       if (ThumbnailViewUI.this.h != null)
/* 657:    */       {
/* 658:529 */         int i = ((DefaultListModel)ThumbnailViewUI.this.h.getModel()).indexOf(localVirtualFile);
/* 659:530 */         if (i != -1)
/* 660:    */         {
/* 661:531 */           Rectangle localRectangle = ThumbnailViewUI.this.h.getCellBounds(i, i);
/* 662:532 */           ThumbnailViewUI.this.h.repaint(localRectangle);
/* 663:    */         }
/* 664:    */       }
/* 665:    */     }
/* 666:    */     
/* 667:    */     public void fileDeleted(@NotNull VirtualFileEvent paramVirtualFileEvent)
/* 668:    */     {
/* 669:538 */       if (paramVirtualFileEvent == null) {
/* 670:538 */         throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/images/thumbnail/impl/ThumbnailViewUI$VFSListener", "fileDeleted" }));
/* 671:    */       }
/* 672:538 */       VirtualFile localVirtualFile1 = paramVirtualFileEvent.getFile();
/* 673:539 */       VirtualFile localVirtualFile2 = ThumbnailViewUI.this.d.getRoot();
/* 674:540 */       if ((localVirtualFile2 != null) && (VfsUtil.isAncestor(localVirtualFile1, localVirtualFile2, false))) {
/* 675:541 */         ThumbnailViewUI.this.refresh();
/* 676:    */       }
/* 677:543 */       if (ThumbnailViewUI.this.h != null) {
/* 678:544 */         ((DefaultListModel)ThumbnailViewUI.this.h.getModel()).removeElement(localVirtualFile1);
/* 679:    */       }
/* 680:    */     }
/* 681:    */     
/* 682:    */     public void propertyChanged(@NotNull VirtualFilePropertyEvent paramVirtualFilePropertyEvent)
/* 683:    */     {
/* 684:549 */       if (paramVirtualFilePropertyEvent == null) {
/* 685:549 */         throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/images/thumbnail/impl/ThumbnailViewUI$VFSListener", "propertyChanged" }));
/* 686:    */       }
/* 687:549 */       ThumbnailViewUI.this.refresh();
/* 688:    */     }
/* 689:    */     
/* 690:    */     public void fileCreated(@NotNull VirtualFileEvent paramVirtualFileEvent)
/* 691:    */     {
/* 692:553 */       if (paramVirtualFileEvent == null) {
/* 693:553 */         throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/images/thumbnail/impl/ThumbnailViewUI$VFSListener", "fileCreated" }));
/* 694:    */       }
/* 695:553 */       ThumbnailViewUI.this.refresh();
/* 696:    */     }
/* 697:    */     
/* 698:    */     public void fileMoved(@NotNull VirtualFileMoveEvent paramVirtualFileMoveEvent)
/* 699:    */     {
/* 700:557 */       if (paramVirtualFileMoveEvent == null) {
/* 701:557 */         throw new IllegalArgumentException(String.format("Argument %s for @NotNull parameter of %s.%s must not be null", new Object[] { "0", "org/intellij/images/thumbnail/impl/ThumbnailViewUI$VFSListener", "fileMoved" }));
/* 702:    */       }
/* 703:557 */       ThumbnailViewUI.this.refresh();
/* 704:    */     }
/* 705:    */     
/* 706:    */     private VFSListener() {}
/* 707:    */   }
/* 708:    */   
/* 709:    */   private final class OptionsChangeListener
/* 710:    */     implements PropertyChangeListener
/* 711:    */   {
/* 712:    */     private OptionsChangeListener() {}
/* 713:    */     
/* 714:    */     public void propertyChange(PropertyChangeEvent paramPropertyChangeEvent)
/* 715:    */     {
/* 716:563 */       Options localOptions = (Options)paramPropertyChangeEvent.getSource();
/* 717:564 */       EditorOptions localEditorOptions = localOptions.getEditorOptions();
/* 718:565 */       TransparencyChessboardOptions localTransparencyChessboardOptions = localEditorOptions.getTransparencyChessboardOptions();
/* 719:566 */       GridOptions localGridOptions = localEditorOptions.getGridOptions();
/* 720:    */       
/* 721:568 */       ImageComponent localImageComponent = ThumbnailViewUI.this.g.getImageComponent();
/* 722:569 */       localImageComponent.setTransparencyChessboardCellSize(localTransparencyChessboardOptions.getCellSize());
/* 723:570 */       localImageComponent.setTransparencyChessboardWhiteColor(localTransparencyChessboardOptions.getWhiteColor());
/* 724:571 */       localImageComponent.setTransparencyChessboardBlankColor(localTransparencyChessboardOptions.getBlackColor());
/* 725:572 */       localImageComponent.setGridLineZoomFactor(localGridOptions.getLineZoomFactor());
/* 726:573 */       localImageComponent.setGridLineSpan(localGridOptions.getLineSpan());
/* 727:574 */       localImageComponent.setGridLineColor(localGridOptions.getLineColor());
/* 728:    */     }
/* 729:    */   }
/* 730:    */   
/* 731:    */   private class FocusRequester
/* 732:    */     extends MouseAdapter
/* 733:    */   {
/* 734:    */     private FocusRequester() {}
/* 735:    */     
/* 736:    */     public void mouseClicked(MouseEvent paramMouseEvent)
/* 737:    */     {
/* 738:580 */       ThumbnailViewUI.this.requestFocus();
/* 739:    */     }
/* 740:    */   }
/* 741:    */ }



/* Location:           E:\idea\

 * Qualified Name:     org.intellij.images.thumbnail.impl.ThumbnailViewUI

 * JD-Core Version:    0.7.0.1

 */